<?php
if(defined('IZ_ACCNAME')) {
$opt_flags = $_SESSION['IZ_OPT'];
if($_GET['act'] == 'manage') {
  if(($_SESSION['canview'] == 1) || ($_SESSION['edit'] > 0) || ($_SESSION['delete'] > 0) || ($_SESSION['cpanel'] == 1)) {
  if(($opt_flags & OPT_FILTERS) != 0) {
    if($_GET['view'] == 'expanded') {
      cat_filter('expanded');
    } else {
      cat_filter('list');
    }
  }
  ?>
  <br />
  <?php if($_SESSION['IZ_REWRITE'] == 'apache') {
    echo '<h3 class="calwrappertext"><strong>',STR_VIEW,'&#58;</strong> <a href="',$_SESSION['IZ_CALURL'],'manage/list/">',STR_VIEWLIST,'</a> &#58;&#58; <a href="',$_SESSION['IZ_CALURL'],'manage/expanded/">',STR_VIEWEXPAND,'</a></h3>';
  } else {
    echo '<h3 class="calwrappertext"><strong>',STR_VIEW,'&#58;</strong> <a href="',$_SESSION['IZ_CALURL'],'index.php&#63;events&#38;act&#61;manage&#38;view&#61;list">',STR_VIEWLIST,'</a> &#58;&#58; <a href="',$_SESSION['IZ_CALURL'],'index.php&#63;events&#38;act&#61;manage&#38;view&#61;expanded">',STR_VIEWEXPAND,'</a></h3>';
  } ?>
  <br />
  <?php 

    if($_GET['view'] != 'expanded') {
      getmassactions();
      if(($_SESSION['delete'] > 0) || ($_SESSION['edit'] > 0) || ($_SESSION['cpanel'] == 1)) {
        echo '<input type="hidden" name="events" value="events" />';
      }
      echo '<input type="hidden" name="from" value="events.act-manage.view-list" />';
    }
    if(($opt_flags & OPT_TODO) != 0) {
      echo '<h2 class="calwrappertext">',STR_TODO,'</h2>
      <div id="listtodo">';
      list_todo();
      echo '</div>
      <br />';
    }
    echo '<h2 class="calwrappertext">',STR_EVENTS,'</h2>
    <div id="listevents">';
    list_events();
    echo '</div>
    </form>';
  } else {
    echo '<span>&#35;114&#58; ',ERR_NOPERMISSION,'</span>';
  }
} elseif($_REQUEST['act'] == 'editevent') {
  if(!empty($_GET['event'])) { 
    $evid = $_GET['event']; 
  } else { 
    $evid = $_POST['id']; 
  }
  izsql();
  if(IZ_CALMODE == 'mysql') {
    if($_SESSION['MYSQLi']) {
      global $dblink;
      $editqry = $dblink->query("SELECT * FROM events WHERE id='$evid'");
      $sqlevent = $editqry->fetch_object();
      $editqry->close();
    } else {
      $editqry = mysql_query("SELECT * FROM events WHERE id='$evid'");
      $sqlevent = mysql_fetch_object($editqry);
    }
  } elseif(IZ_CALMODE == 'postgre') {
    $editqry = pg_query("SELECT * FROM \"events\" WHERE \"id\"='$evid'");
    $sqlevent = pg_fetch_object($editqry);
  } elseif(IZ_CALMODE == 'msq') {
    $editqry = mssql_query("SELECT * FROM events WHERE id='$evid'");
    $sqlevent = mssql_fetch_object($editqry);
  }
  $event = new event($sqlevent);
  if($_SESSION['cpanel'] == 1
       || $_SESSION['edit'] == 2
       || ($_SESSION['edit'] == 1
           && (strtolower($event->author) == strtolower($_SESSION['uname']))
               || (strtolower($event->author) == 'everyone')
           )
     ) {
    if(empty($event->title)) {
        echo '<div id="errorbox2"><p>',ERR_EVNOTFOUND,'</p></div>';
    } else {
?>

<div class="containerbox" id="eventform">
    <form enctype="multipart/form-data" method="post" action="<?php echo $_SESSION['IZ_CALURL']; ?>index.php" id="editevent" name="editevent" onsubmit="return validate_event('edit');">
        <div class="containertitle"><?php echo STR_EDITEVENT; ?></div>
	    <label for="editevtitle"><?php echo STR_EVENTNAME; ?>&#58;</label>
	    <input type="text" name="editevtitle" id="editevtitle" class="standard" size="30" value="<?php echo $event->title; ?>" />
        <div class="inlineerror" id="editeverror_title">&nbsp;</div><br /> 
      <?php if(($opt_flags & OPT_ENDDATE) != 0) { ?> 
      <label for="startbox"><?php echo STR_STARTS; ?>&#58;<br />
          <small><?php echo STR_ALLDAYINST; ?></small>
      </label>
      <div class="datebox" id="editevstartbox">
          <div class="dateinput"><input type="text" name="editevstartdate" size="10" id="editevstartdate" class="standard" value="<?php echo date("j/m/Y",$event->eventstart); ?>" /><img src="<?php echo $_SESSION['IZ_CALURL']; ?>images/calendar.png" class="datepicker" alt="<?php echo STR_PICKSTART; ?>" id="editevstartmousehook" /></div>
          <div class="dateinput">    
              <input type="text" name="editevstarthour" size="2" id="editevstarthour" class="small" value="<?php echo date('H',$event->eventstart); ?>"<?php if($event->allday == 1) { echo 'disabled="disabled"'; } ?> />
              &#58;
              <input type="text" name="editevstartminute" size="2" id="editevstartminute" class="small" value="<?php echo date('i',$event->eventstart); ?>"<?php if($event->allday == 1) { echo 'disabled="disabled"'; } ?> />
          </div>
          <div><input type="checkbox" name="editevallday" id="editevallday" class="inlinecheck" value="1"<?php if(intval($event->allday) == 1) { echo ' checked="checked"'; } ?> onchange="setallday('main','edit');" /><label for="editevallday"><?php echo STR_ALLDAYDESC; ?></label></div>
          <div class="inlineerror" id="editeverror_start">&nbsp;</div>
          <div class="inlineerror" id="editeverror_allday" style="padding-top: 2px;">&nbsp;</div>
      </div><br />

      <label for="editevenddate"><?php echo STR_ENDS; ?>&#58;</label>
      <div class="datebox">
          <div class="dateinput"><input type="text" name="editevenddate" size="10" id="editevenddate" class="standard" value="<?php echo date("j/m/Y",$event->eventend); ?>" /><img src="<?php echo $_SESSION['IZ_CALURL']; ?>images/calendar.png" class="datepicker" alt="<?php echo STR_PICKEND; ?>" id="editevendmousehook" /></div>
          <div class="dateinput">
              <input type="text" name="editevendhour" size="2" id="editevendhour" class="small" value="<?php echo date('H',$event->eventend); ?>"<?php if($event->allday == 1) { echo 'disabled="disabled"'; } ?> />
              &#58;
              <input type="text" name="editevendminute" size="2" id="editevendminute" class="small" value="<?php echo date('i',$event->eventend); ?>"<?php if($event->allday == 1) { echo 'disabled="disabled"'; } ?> />
          </div>
          <div class="inlineerror" id="editeverror_end">&nbsp;</div>
      </div><br />
    <?php
    $cals .= 'Calendar.setup({inputField:"editevstartdate",button:"editevstartmousehook",displayArea:"editvstartmousehook",onUpdate:function() {document.getElementById(\'editevenddate\').value = document.getElementById(\'editevstartdate\').value }});'."\n".
             'Calendar.setup({inputField:"editevenddate",button:"editevendmousehook",displayArea:"editvendmousehook"});';
    } else {
    $cals .= 'Calendar.setup({inputField:"editevstartdate",button:"editevstartmousehook",displayArea:"editvstartmousehook"});'."\n";
    ?>
      <label for="startbox"><?php echo STR_DATE; ?>&#58;</label>
      <div class="datebox" id="editevstartbox">
          <div class="dateinput"
          <input type="text" name="editevstartdate" size="10" id="editevstartdate" class="standard" value="<?php echo date("j/m/Y",$event->eventstart); ?>" />
          <img src="<?php echo $_SESSION['IZ_CALURL']; ?>images/calendar.png" class="datepicker" alt="<?php echo STR_PICKSTART; ?>" id="editevstartmousehook" />
          </div>
      </div><br />
    <?php } ?>

	    <label for="editevtask"><?php echo STR_DESCRIPTION; ?>&#58;</label>
	    <textarea rows="20" name="editevtask" id="editevtask" class="standard mceEditor" cols="60"><?php echo dirty($event->description); ?></textarea><br />

      <?php if(($opt_flags & OPT_ATTENDEES) != 0) { ?>
 	        <label for="editevattendees"><?php echo STR_ATTENDEES; ?>&#58;</label>
	        <textarea rows="4" name="editevattendees" id="editevattendees" class="standard" cols="60"><?php echo $event->attendees; ?></textarea><br />
	        <div class="datebox"><input type="checkbox" name="resend" id="resend" class="optioncheck" value="1" /><label for="resend"><?php echo STR_INVITESSEND; ?></label></div><br />
	    <?php } ?>

	    <?php if($_SESSION['cust1'] != 'none') { ?>
	    <label for="editevcust1"><?php echo $_SESSION['cust1']; ?>&#58;</label>
	    <input type="text" name="editevcust1" id="editevcust1" size="50" class="standard" value="<?php echo $event->cust1; ?>" /><br />

	    <?php } if($_SESSION['cust2'] != 'none') { ?>
	    <label for="editevcust2"><?php echo $_SESSION['cust2']; ?>&#58;</label>
	    <input type="text" name="editevcust2" id="editevcust2" size="50" class="standard" value="<?php echo $event->cust2; ?>" /><br />

	    <?php } if($_SESSION['cust3'] != 'none') { ?>
	    <label for="editevcust3"><?php echo $_SESSION['cust3']; ?>&#58;</label>
	    <input type="text" name="editevcust3" id="editevcust3" size="50" class="standard"  value="<?php echo $event->cust3; ?>" /><br />
	    <?php } ?>

	    <?php if(($opt_flags & OPT_VENUE) != 0) { ?>
	    <label for="editevvenue"><?php echo STR_VENUE; ?>&#58;</label>
	    <input type="text" name="editevvenue" id="editevvenue" size="30" class="standard" value="<?php echo $event->venue; ?>" /><br />
	    <?php if(($opt_flags & OPT_GOOGLE) != 0) { ?>
  	      <div class="datebox">
  	        <input type="checkbox" name="editevlinkgoogle" id="editevlinkgoogle" class="optioncheck" value="1"<?php if($event->linkgoogle == 1) { echo ' checked="checked"'; } ?> />
  	        <label for="linkgoogle"><?php echo STR_LINKGOOGLE; ?></label>
  	      </div><br />
  	    <?php } } ?>

	    <?php if($_SESSION['cpanel'] == 1) { ?>
	    <label for="editevauthor"><?php echo STR_AUTHOR; ?>&#58; </label>
	    <?php
              if(strtolower($event->author) == 'everyone') {
                echo STR_NOTLOGGEDIN;
              } else {
                echo dirty($event->author);
              }
            ?><br />
	    <?php } ?>

	    <?php if(($opt_flags & OPT_CATEGORY) != 0) {
	    $onload .= 'listen(\'click\',\'editevcategory\',addnewcatfunc(\'event\',\'edit\'));'."\n"; ?>
      <label for="editevcategory"><?php echo STR_CATEGORY; ?>&#58;</label>
      <select name="editevcategory" id="editevcategory" size="1">
      <?php get_categories('edit',$event->category,'event'); ?>
      <option id="editnewcatevent" value="newcat"><?php echo STR_NEWCATEGORY; ?></option>
      </select><br />
      <?php } else { ?>
      <input type="hidden" name="editevcategory" id="editevcategory" value="<?php echo $_SESSION['defaultcategoryevents']; ?>" />
      <?php } ?>
      
      <?php if(($opt_flags & OPT_ICON) != 0) { ?>
      <label><?php echo STR_ICON; ?>&#58;</label>
      <div class="icon-box">
      <?php get_icons('edit','event',$event->icon); ?>
      </div><br />
      <?php } ?>

    <?php if($_SESSION['authed'] == 1) { ?>
      <label><?php echo STR_EVENTSTATUS; ?>&#58;</label>
	    <div class="checks">
	      <input type="radio" value="Public" name="editevstatus" class="nomargin" id="editevpublicstatus"<?php if($event->status == 'Public') { echo ' checked="checked"'; } ?> /><label for="editevpublicstatus" class="plain"><?php echo STR_STATUSPUBLIC; ?></label>
	      <input type="radio" value="Private" name="editevstatus" class="nomargin" id="editevprivatestatus"<?php if($event->status == 'Private') { echo ' checked="checked"'; } ?> /><label for="editevprivatestatus" class="plain"><?php echo STR_STATUSPRIVATE; ?></label>
      </div><br />
    <?php } else { ?>
      <input type="hidden" name="editevstatus" value="Public" />
    <?php } if($_SESSION['IZ_ALLOWCOMMENTS'] == 'author') { ?>
      <label><?php echo STR_ALLOWCOMMENTS; ?>&#58;</label>
      <div><input type="checkbox" name="editevallowcomments" id="editevallowcomments" class="inlinecheck" <?php if($event->comments) { echo 'checked="checked" '; } ?>tabindex="19" value="1" />
      <label for="editevallowcomments" class="plain"><?php echo STR_ENABLED; ?></label></div><br />
    <?php } if($event->instanceof != 'none' && strlen(trim($event->instanceof)) > 0) { getserieslength($event->instanceof, 'p'); } ?>
		  <div class="actions">
    <?php
    if(($_SESSION['cpanel'] == 1) || (($_SESSION['delete'] == 1) && (strtolower($event->author) == strtolower($_SESSION['uname']) || (strtolower($event->author) == 'everyone'))) || ($_SESSION['delete'] == 2)) {
      if($event->instanceof != 'none' && strlen(trim($event->instanceof)) > 0) {
        echo '<input type="submit" value="',STR_DELSERIES,'" name="delseries" class="buttondelete" />';
      }
      echo '<input type="submit" value="',STR_DELETE,'" name="delevent" class="buttondelete" />';
    }
    if(($_SESSION['cpanel'] == 1) || (($_SESSION['edit'] == 1) && ((strtolower($event->author) == strtolower($_SESSION['uname']) || (strtolower($event->author) == 'everyone')))) || ($_SESSION['edit'] == 2)) {
      echo '<button type="submit" value="save" name="store" class="buttonsave">',STR_SAVE,'</button>';
      if($event->instanceof != 'none' && strlen(trim($event->instanceof)) > 0) {
        echo '<button type="submit" value="save" name="saveseries" class="buttonsave">',STR_SAVESERIES,'</button>';
      }
    } ?>
      </div>
    <?php if(isset($_POST['from'])) { echo '<input type="hidden" name="from" value="',$_POST['from'],'" />'; }
          if(strlen(trim($event->instanceof)) != 0) {
            echo '<input type="hidden" name="instanceof" value="',$event->instanceof,'" />';            
          }
    ?>
      <input type="hidden" name="act" value="editevent" />
      <input type="hidden" name="events" value="events" />
      <input type="hidden" name="id" value="<?php echo $evid; ?>" />
      <input type="hidden" name="author" value="<?php echo $event->author; ?>" />
    </form>
</div>
<?php }
 } else {
   echo '<span>&#35;110&#58; ',ERR_NOPERMISSION,'</span>';
 } 
} elseif($_GET['act'] == 'viewevent') {
    $evid = $_GET['event'];
    izsql();
    if(IZ_CALMODE == 'mysql') {
      if($_SESSION['MYSQLi']) {
        global $dblink;
        $editqry = $dblink->query("SELECT * FROM events WHERE id='$evid'");
        $sqlevent = $editqry->fetch_object();
        $editqry->close();
      } else {
        $editqry = mysql_query("SELECT * FROM events WHERE id='$evid'");
        $sqlevent = mysql_fetch_object($editqry);
      }
    } elseif(IZ_CALMODE == 'postgre') {
      $editqry = pg_query("SELECT * FROM \"events\" WHERE \"id\"='$evid'");
      $sqlevent = pg_fetch_object($editqry);
    } elseif(IZ_CALMODE == 'msq') {
      $editqry = mssql_query("SELECT * FROM events WHERE id='$evid'");
      $sqlevent = mssql_fetch_object($editqry);
    }
    $event = new event($sqlevent);
    if(empty($event->title)) {
        echo '<div id="errorbox2"><p>',ERR_EVNOTFOUND,'</p></div>';
    } else if(($_SESSION['cpanel'] == 1) 
        || $event->status == 'Public'
        || ($event->status == 'Private'
            && (strtolower($event->author) == strtolower($_SESSION['uname'])
            || (strtolower($event->author) == 'everyone')
           )
        )) {
      if($_SESSION['cpanel'] == 1
         || $_SESSION['edit'] == 2
         || ($_SESSION['edit'] == 1
             && (strtolower($event->author) == strtolower($_SESSION['uname']))
                 || (strtolower($event->author) == 'everyone')
             )
       ) {
$onload .= 'new Ajax.InPlaceEditor(\'eventtitle\',\''.$_SESSION['IZ_CALURL'].'\',{
  highlightcolor:\'transparent\',
  onFailure: function(blah, t) {alert(t.responseText);},
  callback: function(form, value) { return \'ajax=1&inline=1&type=e&id='.$event->id.'&title=\'+escape(value) },
  okText: \''.STR_OK.'\',
  cancelText: \''.STR_CANCEL.'\',
  savingText: \''.STR_SAVING.'\',
  loadingText: \''.STR_LOADING.'\',
  cancelControl: \'button\',
  highlightcolor: \''.($_SESSION['IZ_CURTHEME'] == 'charcoal' ? '#3e3e3e' : '#fffddd').'\',
  ajaxOptions: {method: \'get\'}
});'
/*new Ajax.InPlaceEditor(\'eventdescription\',\''.$_SESSION['IZ_CALURL'].'\',{
  highlightcolor:\'transparent\',
  onFailure: function(blah, t) { alert(t.responseText); },
  onEnterEditMode: function(form, value) { tinyMCE.execCommand(\'mceAddControl\', false, \'txaEditableContent\'); },
  callback: function(form, value) { return \'ajax=1&inline=1&type=e&id='.$event->id.'&description=\'+escape(value) },
  loadTextURL: \''.$_SESSION['IZ_CALURL'].'?ajax=1&inline=1&type=e&request=description&id='.$event->id.'\',
  rows: 8,
  cols: 30,
  okText: \''.STR_OK.'\',
  cancelText: \''.STR_CANCEL.'\',
  savingText: \''.STR_SAVING.'\',
  loadingText: \''.STR_LOADING.'\',
  cancelControl: \'button\',
  ajaxOptions: {method: \'get\'}
});'*/."\n";
      }
?>
<table class="containerbox viewevent" style="vertical-align: top;">
	<tr>
		<td class="containertitle" colspan="2"><?php echo STR_VIEWINGEVENT; ?></td>
	</tr>
	<tr>
		<td class="formheading" width="20%"><?php echo STR_EVENTNAME; ?>&#58; </td>
		<td><?php 
  		if(($opt_flags & OPT_ICON) != 0 && intval($event->icon) != -1) {
        echo '<img src="',$_SESSION['IZ_CALURL'],'/images/icons/',$icons[$event->icon],'" class="icon" /><span id="eventtitle">';
      }
  		echo $event->title; 
    ?></span></td>
	</tr>
	<?php if((!empty($event->venue)) && (($opt_flags & OPT_VENUE) != 0)) { ?>
	<tr>
		<td class="formheading"><?php echo STR_VENUE; ?>&#58; </td>
		<td><?php if(($event->linkgoogle == 1) && (($opt_flags & OPT_GOOGLE) != 0)) {
		            echo '<a href="http://maps.google.co.uk/maps?q=',dirty($event->venue),'" title="'.STR_LINKGOOGLE,'"',(($opt_flags & OPT_GOOGLENEWWINDOW) != 0 ? ' target="_blank"' : ''),'>',$event->venue,'</a>';
			  } else {
			    echo $event->venue;
			  } ?></td>
	</tr>
	<?php } if(($opt_flags & OPT_CATEGORY) != 0) { ?>
	<tr>
		<td class="formheading"><?php echo STR_CATEGORY; ?>&#58; </td>
		<?php 
    if(empty($_SESSION['eventcats'][$event->category]->name)) {
      echo '<td>',STR_PRIVATE,'</td>';
    } else {
      if($_SESSION['IZ_REWRITE'] == 'apache') {
  		  echo '<td><a href="',$_SESSION['IZ_CALURL'],'category/',$event->category,'/">',$_SESSION['eventcats'][$event->category]->name,'</a></td>';
  		} else {
  		  echo '<td><a href="',$_SESSION['IZ_CALURL'],'index.php?category=',$event->category,'">',$_SESSION['eventcats'][$event->category]->name,'</a></td>';
  		} 
		} ?>
	</tr>
	<?php } if(($opt_flags & OPT_ENDDATE) != 0) { ?>
	<tr>
		<td class="formheading"><?php echo STR_STARTS; ?>&#58; </td>
		<td><?php 
        	if($event->allday == 1) {
 	            echo '<a href="',getlink('day',date('j',$event->eventstart),date('n',$event->eventstart),date('Y',$event->eventstart)),'">',iz_longdate($event->eventstart),'</a> &#40;',calcduration($event->eventstart,$event->eventend,true,'ext'),'&#41;</td>
	                 </tr><tr>
	                   <td class="formheading">',STR_ENDS,'&#58; </td>
	   	  	   <td><a href="',getlink('day',date('j',$event->eventend),date('n',$event->eventend),date('Y',$event->eventend)),'">',iz_longdate($event->eventend),'</a>';
		      } else {
        	    echo '<a href="',getlink('day',date('j',$event->eventstart),date('n',$event->eventstart),date('Y',$event->eventstart)),'">',iz_longdatehours($event->eventstart),'</a></td>
		         </tr><tr>
               <td class="formheading">',STR_ENDS,'&#58; </td>
	   	  	     <td><a href="',getlink('day',date('j',$event->eventend),date('n',$event->eventend),date('Y',$event->eventend)),'">',iz_longdatehours($event->eventend),'</a>';
	        }
        	?></td>
	</tr>
	<?php } else { ?>
	<tr>
		<td class="formheading"><?php echo STR_DATE; ?>&#58; </td>
		<td><?php echo '<a href="',getlink('day',date('j',$event->eventstart),date('n',$event->eventstart),date('Y',$event->eventstart)),'">',iz_longdate($event->eventstart),'</a>'; ?></td>
	</tr>
	<?php } if(!empty($event->description)) { ?>
	<tr>
		<td class="formheading"><?php echo STR_DESCRIPTION; ?>&#58; </td>
		<td><div class="description"><span id="eventdescription"><?php echo $event->description; ?></span></div></td>
	</tr>
	<?php } if(!empty($event->attendees) && ($opt_flags & OPT_ATTENDEES) != 0) {
	   echo '<tr><td class="formheading">',STR_ATTENDEES,'&#58; </td>
		<td>',str_replace(",","<br />",$event->attendees),'</td>
	</tr>';
	} ?>
    <?php 
    if($_SESSION['cust1'] != 'none') {
        echo '<tr><td class="formheading">',$_SESSION['cust1'],'&#58; </td><td>',$event->cust1,'</td></tr>';
    }
    if($_SESSION['cust2'] != 'none') {
        echo '<tr><td class="formheading">',$_SESSION['cust2'],'&#58; </td><td>',$event->cust2,'</td></tr>';
    }
     if($_SESSION['cust3'] != 'none') {
        echo '<tr><td class="formheading">',$_SESSION['cust3'],'&#58; </td><td>',$event->cust3,'</td></tr>';
    }
     if($_SESSION['cpanel'] == 1) {
        if(strtolower($event->author) == 'everyone') {
          echo '<tr><td class="formheading">',STR_AUTHOR,'&#58; </td><td>',STR_NOTLOGGEDIN,'</td></tr>';
        } else {
          echo '<tr><td class="formheading">',STR_AUTHOR,'&#58; </td><td>',$event->author,'</td></tr>';
        }
    }
    if(strlen(trim($event->instanceof)) != 0) { getserieslength($event->instanceof, 'table'); }
  	if(($_SESSION['edit'] > 0) || ($_SESSION['delete'] > 0) || ($_SESSION['cpanel'] == 1)) {
        echo '<tr><td colspan="2" style="border-top: 1px solid #000; padding-top: 0;"><form method="post" action="',$_SESSION['IZ_CALURL'],'index.php" id="event" name="event"><div class="actions" style="border-top: 0;">';
            if(($_SESSION['cpanel'] == 1) || (($_SESSION['delete'] == 1) && (strtolower($event->author) == strtolower($_SESSION['uname']) || (strtolower($event->author) == 'everyone'))) || ($_SESSION['delete'] == 2)) {
              if(strlen(trim($event->instanceof)) != 0) {
                echo '<input type="hidden" name="instanceof" value="',$event->instanceof,'" />
                <button type="submit" value="delete" name="delseries" class="buttondelete">',STR_DELSERIES,'</button>';
              }
              echo '<button type="submit" value="delete" name="delevent" class="buttondelete">',STR_DELETE,'</button>';
            }
            if(($_SESSION['edit'] == 1 && ((strtolower($event->author) == strtolower($_SESSION['uname'])) || ($event->author == 'everyone'))) || ($_SESSION['edit'] == 2) || ($_SESSION['cpanel'] == 1) || (($event->status == 'Private') && ($event->author == strtolower($_SESSION['uname'])))) {
            
              echo '<input type="submit" value="',STR_EDIT,'" name="',STR_EDIT,'" class="buttonedit" />';
            } 
        echo '<input type="hidden" name="events" value="events" />
            <input type="hidden" name="from" value="',$_GET['from'],'" />
            <input type="hidden" name="act" value="editevent" />
            <input type="hidden" name="id" value="',$evid,'" />
            <input type="hidden" name="file" value="',$filetouse,'" />
            </div></form></td></tr>';
    } ?>
</table>
    <?php if($_SESSION['IZ_ALLOWCOMMENTS'] != 0) { ?>
    <br />
    <?php 
          if(($_SESSION['IZ_ALLOWCOMMENTS']) || ($event->comments)) {
            echo getcomments($evid);
            echo getcommentform($evid,'event');
          }
        }
  } else {
      echo '<span>&#35;111&#58; ',ERR_NOPERMISSION,'</span>';
  }
} elseif($_REQUEST['act'] == 'edittodo') {
    $id = $_REQUEST['id'];
    izsql();
    if(IZ_CALMODE == 'mysql') {
      if($_SESSION['MYSQLi']) {
        global $dblink;
        $qry = $dblink->query(sprintf("SELECT * FROM tasks WHERE id='%s'",
                                      $dblink->real_escape_string($id)));
        $sqltodo = $qry->fetch_object();
        $qry->close();
      } else {
        $qry = mysql_query(sprintf("SELECT * FROM tasks WHERE id='%s'",
                                    mysql_real_escape_string($id)));
        $sqltodo = mysql_fetch_object($qry);
      }
    } elseif(IZ_CALMODE == 'postgre') {
      $qry = pg_query(sprintf("SELECT * FROM \"tasks\" WHERE \"id\"='%s'",
                              pg_escape_string($id)));
      $sqltodo = pg_fetch_object($qry);
    } elseif(IZ_CALMODE == 'msq') {
      $qry = mssql_query(sprintf("SELECT * FROM tasks WHERE id='%s'",
                                 mssql_escape_string($id)));
      $sqltodo = mssql_fetch_object($qry);
    }
    if(is_resource($qry) || is_object($sqltodo)) {
      $todo = new todo($sqltodo);
    }
    if(($_SESSION['edit'] > 0 && $todo->status == 'Public') || ($_SESSION['edit'] == 2) || ($_SESSION['cpanel'] == 1) || (($todo->status == 'Private') && (strtolower($todo->author) == strtolower($_SESSION['uname'])) || (strtolower($todo->author) == 'everyone'))) {
      if(empty($todo->id)) {
          echo '<div id="errorbox2"><p>',ERR_EVNOTFOUND,'</p></div>';
      } else {
        $onload .= 'listen(\'click\',\'edittaskongoing\',ongoingfunc(\'main\',\'edit\'));'."\n";
        $cals .= 'Calendar.setup({inputField:"edittaskdatedue",button:"edittaskdateduehook",displayArea:"edittaskdateduehook"});'."\n";
      ?>
<div class="containerbox" id="todoform">
    <form enctype="multipart/form-data" method="post" action="<?php echo $_SESSION['IZ_CALURL']; ?>index.php" id="edittodo" name="edittodo" onsubmit="return validate_todo('edit');">
        <div class="containertitle"><?php echo STR_EDITTASK; ?></div>
              <label for="edittaskname"><?php echo STR_TASKNAME; ?>&#58;</label>
              <input type="text" name="edittaskname" tabindex="2" id="edittaskname" class="standard" size="30" value="<?php echo $todo->title; ?>" />
              <div class="inlineerror" id="editerror_taskname">&nbsp;</div><br />
      
              <label for="edittaskdatedue"><?php echo STR_DATEDUE; ?>&#58;</label>
              <div class="datebox">
                <input type="text" name="edittaskdatedue" tabindex="4" size="10" id="edittaskdatedue" class="standard" <?php if($todo->due == 0) { echo 'disabled="disabled"'; } else { echo 'value="',date("j/m/Y",$todo->due),'" '; } ?>/><img src="<?php echo $_SESSION['IZ_CALURL']; ?>images/calendar.png" class="datepicker" id="edittaskdateduehook" alt="<?php echo STR_DATEDUE; ?>" />
              </div><br />
              <div class="datebox">
                <input type="checkbox" name="edittaskongoing" id="edittaskongoing" class="optioncheck" tabindex="5" value="1"<?php if($todo->due == 0) { echo 'checked="checked"'; } ?> />
                <label for="edittaskongoing" class="plain"><?php echo STR_ONGOING; ?></label>
              </div><br />
              <div class="inlineerror" id="editerror_datedue">&nbsp;</div>
              <br />
                   
              <label for="edittaskdesc"><?php echo STR_TASK; ?>&#58;</label>
              <textarea rows="20" name="edittaskdesc" tabindex="7" id="edittaskdesc" class="standard mceEditor" cols="60"><?php echo dirty($todo->description); ?></textarea><br />

              <?php if(($opt_flags & OPT_CATEGORY) != 0) {
              $onload .= 'listen(\'click\',\'edittaskcategory\',addnewcatfunc(\'todo\',\'edit\'));'."\n"; ?>
              <label for="edittaskcategory"><?php echo STR_CATEGORY; ?>&#58;</label>
              <select name="edittaskcategory" id="edittaskcategory" size="1">
              <?php get_categories('edit',$todo->category,'task'); ?>
              <option id="editnewcattodo" value="newcat"><?php echo STR_NEWCATEGORY; ?></option>
              </select>
  	          <br />
      
              <?php } if(($opt_flags & OPT_ICON) != 0) { ?>
              <label><?php echo STR_ICON; ?>&#58;</label>
              <div class="icon-box">
              <?php get_icons('edit','task',$todo->icon); ?>
              </div><br />
              
              <?php } if($_SESSION['authed'] == 1) { ?>
              <label><?php echo STR_TASKSTATUS; ?>&#58;</label>
        		  <div class="checks">
        		      <input type="radio" value="Public" name="edittaskstatus" tabindex="5" class="nomargin" id="edittaskpublicstatus"<?php if($_SESSION['defaultstatus'] == 'Public') { echo ' checked="checked"'; } ?> /><label for="edittaskpublicstatus" class="plain"><?php echo STR_STATUSPUBLIC; ?></label>
        		      <input type="radio" value="Private" name="edittaskstatus" tabindex="6" class="nomargin" id="edittaskprivatestatus"<?php if($_SESSION['defaultstatus'] == 'Private') { echo ' checked="checked"'; } ?> /><label for="edittaskprivatestatus" class="plain"><?php echo STR_STATUSPRIVATE; ?></label>
  	     	    </div><br />
  	     	    <?php } else { ?>
                        <input type="hidden" name="edittaskstatus" value="Public" />
              <?php } ?>
      
        	    <?php } if($_SESSION['cust1'] != 'none') { ?>
        	    <label for="edittaskcust1"><?php echo $_SESSION['cust1']; ?>&#58;</label>
        	    <input type="text" name="edittaskcust1" id="edittaskcust1" size="50" class="standard" value="<?php echo dirty($todo->cust1); ?>" /><br />
        
        	    <?php } if($_SESSION['cust2'] != 'none') { ?>
        	    <label for="edittaskcust2"><?php echo $_SESSION['cust2']; ?>&#58;</label>
        	    <input type="text" name="edittaskcust2" id="edittaskcust2" size="50" class="standard" value="<?php echo dirty($todo->cust2); ?>" /><br />
        
        	    <?php } if($_SESSION['cust3'] != 'none') { ?>
        	    <label for="edittaskcust3"><?php echo $_SESSION['cust3']; ?>&#58;</label>
        	    <input type="text" name="edittaskcust3" id="edittaskcust3" size="50" class="standard"  value="<?php echo dirty($todo->cust3); ?>" /><br />
        	    
        	    <?php } if($_SESSION['IZ_ALLOWCOMMENTS'] == 'author') { ?>
	            <label><?php echo STR_ALLOWCOMMENTS; ?>&#58;</label>
 		          <div><input type="checkbox" name="edittaskallowcomments" id="edittaskallowcomments" class="inlinecheck" <?php if($todo->comments) { echo 'checked="checked" '; } ?>tabindex="19" value="1" />
  	            <label for="edittaskallowcomments" class="plain"><?php echo STR_ENABLED; ?></label></div><br />

              <?php } if($_SESSION['cpanel'] == 1) { ?>
              <label><?php echo STR_AUTHOR; ?>&#58; </label>
              <?php if(strtolower($todo->author) == 'everyone') {
                echo STR_NOTLOGGEDIN; 
              } else { 
                echo $todo->author;
              } ?><br />
      	      <?php } ?>
              
      	<div class="actions">
            <?php
            if(($_SESSION['cpanel'] == 1) 
              || (($_SESSION['delete'] == 1) 
                  && ((strtolower($todo->author) == strtolower($_SESSION['uname'])) 
                     )
                 ) 
              || ($_SESSION['delete'] == 2)
              ) {
              echo '<input type="submit" value="',STR_DELETE,'" name="deltodo" class="buttondelete" />';
            } ?>      	
      	    <input type="submit" value="<?php echo STR_SAVE; ?>" tabindex="22" name="store" class="buttonsave" />
      	</div>
        <?php 
          if(!empty($_REQUEST['from'])) {
            echo '<input type="hidden" name="from" value="',$_REQUEST['from'],'" />';
          }
        ?>
        <input type="hidden" name="act" value="submitedittodo" />
        <input type="hidden" name="todo" value="todo" />
        <input type="hidden" name="id" value="<?php echo $id; ?>" /> 
        </form>
</div>  
<?php } else {
   echo '<span>&#35;112&#58; ',ERR_NOPERMISSION,'</span>';
 }
} elseif($_REQUEST['act'] == 'viewtodo') {
    $id = $_REQUEST['id'];
    izsql();
    if(IZ_CALMODE == 'mysql') {
      if($_SESSION['MYSQLi']) {
        global $dblink;
        $qry = $dblink->query("SELECT * FROM tasks WHERE id='$id'");
        $sqltodo = $qry->fetch_object();
        $qry->close();
      } else {
        $qry = mysql_query("SELECT * FROM tasks WHERE id='$id'");
        $sqltodo = mysql_fetch_object($qry);
      }
    } elseif(IZ_CALMODE == 'postgre') {
      $qry = pg_query("SELECT * FROM \"tasks\" WHERE \"id\"='$id'");
      $sqltodo = pg_fetch_object($qry);
    } elseif(IZ_CALMODE == 'msq') {
      $qry = mssql_query("SELECT * FROM tasks WHERE id='$id'");
      $sqltodo = mssql_fetch_object($qry);
    }
    if(is_resource($qry) || is_object($sqltodo)) {
      $todo = new todo($sqltodo);
    }
    if(empty($todo->id)) {
        echo '<div id="errorbox2"><p>',ERR_EVNOTFOUND,'</p></div>';
    } elseif($_SESSION['cpanel'] == 1
             || $_SESSION['edit'] == 2
             || ($_SESSION['edit'] == 1
                 && (strtolower($todo->author) == strtolower($_SESSION['uname']))
                     || (strtolower($todo->author) == 'everyone')
                 )
           ) {
$onload .= 'new Ajax.InPlaceEditor(\'tasktitle\',\''.$_SESSION['IZ_CALURL'].'\',{
  highlightcolor:\'transparent\',
  onFailure: function(blah, t) {alert(t.responseText);},
  callback: function(form, value) { return \'ajax=1&inline=1&type=t&id='.$todo->id.'&title=\'+escape(value) },
  okText: \''.STR_OK.'\',
  cancelText: \''.STR_CANCEL.'\',
  savingText: \''.STR_SAVING.'\',
  loadingText: \''.STR_LOADING.'\',
  cancelControl: \'button\',
  highlightcolor: \''.($_SESSION['IZ_CURTHEME'] == 'charcoal' ? '#3e3e3e' : '#fffddd').'\',
  ajaxOptions: {method: \'get\'}
});'
/*new Ajax.InPlaceEditor(\'taskdescription\',\''.$_SESSION['IZ_CALURL'].'\',{
  highlightcolor:\'transparent\',
  onFailure: function(blah, t) {alert(t.responseText);},
  callback: function(form, value) { return \'ajax=1&inline=1&type=t&id='.$todo->id.'&description=\'+escape(value) },
  loadTextURL: \''.$_SESSION['IZ_CALURL'].'?ajax=1&inline=1&type=t&request=description&id='.$todo->id.'\',
  rows: 8,
  cols: 30,
  okText: \''.STR_OK.'\',
  cancelText: \''.STR_CANCEL.'\',
  savingText: \''.STR_SAVING.'\',
  loadingText: \''.STR_LOADING.'\',
  cancelControl: \'button\',
  ajaxOptions: {method: \'get\'}
});'*/."\n";
           }
    ?>
    <table class="containerbox viewtask" style="vertical-align: top;">
	<tr>
		<td class="containertitle" colspan="2"><?php echo STR_VIEWINGTASK; ?></td>
	</tr>    
  <tr>
		<td class="formheading" width="20%"><?php echo STR_TASKNAME; ?>&#58;</td>
		<td><?php 
  		if(($opt_flags & OPT_ICON) != 0 && intval($todo->icon) != -1) {
        echo '<img src="',$_SESSION['IZ_CALURL'],'/images/icons/',$icons[$todo->icon],'" class="icon" />';
      }
		echo '<span id="tasktitle">',$todo->title; ?></span></td>
	</tr>
    <tr>
		<td class="formheading"><?php echo STR_DATEDUE; ?>&#58;</td>
		<td><?php if($todo->due == 0) {
			    echo STR_ONGOING;
			  } else {
			    echo '<a href="',getlink('day',date('j',$todo->due),date('n',$todo->due),date('Y',$todo->due)),'">',iz_longdate($todo->due),'</a>';
			  } 
        if($todo->complete == 1) {
          echo ' &#40;'.STR_COMPLETE.'&#41;'; 
        } ?></td>
	</tr>
    <tr>
		<td class="formheading"><?php echo STR_CATEGORY; ?>&#58;</td>
		<?php 
	   if(empty($_SESSION['todocats'][$todo->category]->name)) {
       echo '<td>',STR_PRIVATE,'</td>';
     } else {
	     if($_SESSION['IZ_REWRITE'] == 'apache') {
         echo '<td><a href="',$_SESSION['IZ_CALURL'],'category/',$todo->category,'/">',$_SESSION['todocats'][$todo->category]->name,'</a></td>';		
       } else {
         echo '<td><a href="',$_SESSION['IZ_CALURL'],'index.php?category=',$todo->category,'">',$_SESSION['todocats'][$todo->category]->name,'</a></td>';
       } 
     } ?>
	</tr>
  <?php if($_SESSION['cpanel'] == 1) { ?>
  <tr>
		<td class="formheading" width="20%"><?php echo STR_AUTHOR; ?>&#58;</td>
		<td><?php 
		if(strtolower($todo->author) == 'everyone') {
		  echo STR_NOTLOGGEDIN;
		} else {
		  echo $todo->author;
		} ?></td>
	</tr>
	<?php } ?>
  <?php if($_SESSION['cust1'] != 'none') { ?>
    <tr>
		<td class="formheading"><?php echo $_SESSION['cust1']; ?>&#58;</td>
		<td><?php echo $todo->cust1; ?></td>
	</tr>
  <?php } if($_SESSION['cust2'] != 'none') { ?>
    <tr>
		<td class="formheading"><?php echo $_SESSION['cust2']; ?>&#58;</td>
		<td><?php echo $todo->cust2; ?></td>
	</tr>
  <?php } if($_SESSION['cust3'] != 'none') { ?>
    <tr>
		<td class="formheading"><?php echo $_SESSION['cust3']; ?>&#58;</td>
		<td><?php echo $todo->cust3; ?></td>
	</tr>
  <?php } ?>
    <tr>
		<td class="formheading"><?php echo STR_TASK; ?>&#58;</td>
		<td><div class="description"><span id="taskdescription"><?php echo $todo->description; ?></span></div></td>
	</tr>
  <?php if(($_SESSION['edit'] > 0) || ($_SESSION['delete'] > 0) || ($_SESSION['cpanel'] == 1)) { ?>
	<tr><td colspan="2" style="border-top: 1px solid #000; padding-top: 0;">
	    <form method="post" action="<?php echo $_SESSION['IZ_CALURL']; ?>index.php" id="todoactions" name="todoactions">
	        <div class="actions" style="border-top: 0;">
                  <?php if(($_SESSION['cpanel'] == 1) 
                          || (($_SESSION['delete'] == 1) 
                              && ((strtolower($todo->author) == strtolower($_SESSION['uname'])) 
//                                  || (strtolower($todo->author) == 'everyone')
                                 )
                             ) 
                          || ($_SESSION['edit'] == 2)
                          ) {
	            	  echo '<button type="submit" value="delete" name="deltodo" class="buttondelete">',STR_DELETE,'</button>';
            	        }
                        if(($_SESSION['cpanel'] == 1) 
                          || (($_SESSION['edit'] == 1) 
                              && ((strtolower($todo->author) == strtolower($_SESSION['uname'])) 
//                                  || (strtolower($todo->author) == 'everyone')
                                 )
                             ) 
                          || ($_SESSION['delete'] == 2)
                          ) {
                          echo '<button type="submit" value="edit" name="edittask" class="buttonedit">',STR_EDIT,'</button>';
                        } ?>
	    <input type="hidden" name="todo" value="todo" />
            <input type="hidden" name="from" value="<?php echo $_GET['from']; ?>" />
            <input type="hidden" name="act" value="edittodo" />
            <input type="hidden" name="id" value="<?php echo $id; ?>" />
            </div></form></td></tr>
        <?php } ?>
    </table>
        <?php if($_SESSION['IZ_ALLOWCOMMENTS'] != '0') { ?>
        <br />
        <?php 
                if(($_SESSION['IZ_ALLOWCOMMENTS'] == 1) || ($todo->comments)) {
                  echo getcomments($id);
                  echo getcommentform($id,'todo');
                }
              } ?>
<?php /*} else {
      echo '<span>&#35;113&#58; ',ERR_NOPERMISSION,'</span>';*/
}

} else {
  // Directly accessed
  header('Location: ../');
} ?>